@extends('back_end.layouts.default_info')

{{-- Web site Title --}}
@section('title')
{{{ Lang::get('general.back_end.food').Lang::get('general.index') }}} :: @parent
@stop
@section('content_header')
{{{ Lang::get('general.back_end.food').Lang::get('general.index') }}}
@stop
{{-- breadcrumb --}}
@section('breadcrumb')
<li><a href="#"><i class="fa fa-dashboard"></i> {{{ Lang::get('general.back_end.home') }}}</a></li>
<li class="active">{{{ Lang::get('general.back_end.food').Lang::get('general.index') }}}</li>
@stop
{{-- Content --}}
@section('content')

<div class="box box-success box-search">
    {{ Form::open(array('action' => 'BackFoodController@getIndex')) }}
    <div class="box-header" style="cursor: move;">
        <i class="ion ion-clipboard"></i>

        <h3 class="box-title">查询</h3>
        <div class="box-tools pull-right">

        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        {{ $tab_index = 1 ? '' : '' }}
        {{ $tab_index++ }}
        {{ Form::textGroup('name', Food::$column['name'], Input::old('name', isset($links['name']) ? $links['name'] : ''),   $errors, $tab_index++) }}

        {{ Form::textBetweenGroup('original_price', Food::$column['original_price'], isset($links['original_price_start']) ? $links['original_price_start'] : '', isset($links['original_price_end']) ? $links['original_price_end'] : '', $errors, $tab_index++) }}

        {{ Form::textBetweenGroup('price', Food::$column['price'], isset($links['price_start']) ? $links['price_start'] : '', isset($links['price_end']) ? $links['price_end'] : '', $errors, $tab_index++) }}

        {{ Form::datetimeBetweenGroup('created_at', Food::$column['created_at'], isset($links['created_at_start']) ? $links['created_at_start'] : '', isset($links['created_at_end']) ? $links['created_at_end'] : '', $errors, $tab_index++) }}

        {{ Form::checkboxGroup('status', Food::$column['status'], $status_for_display, $errors, $tab_index++) }}

        {{ Form::checkboxGroup('menu_id', Food::$column['menu_id'], $menus_for_display, $errors, $tab_index++, false, 12) }}

    </div>
    <!-- /.box-body -->
    <div class="box-footer clearfix no-border">
        <button type="submit" class="btn btn-primary pull-left btn-find" style="margin-left: 10px;"><i class="fa fa-search"></i> {{{ Lang::get('button.find') }}}</button>
        <button type="submit" data-type="excel" class="btn btn-default pull-left btn-export" style="margin-left: 10px;"><i class="fa fa-table"></i> {{{ Lang::get('button.export_excel') }}}</button>
        <button type="submit" data-type="csv" class="btn btn-default pull-left btn-export" style="margin-left: 10px;"><i class="fa fa-vimeo-square"></i> {{{ Lang::get('button.export_csv') }}}</button>
    </div>
    {{ Form::close() }}
</div>

<div class="box box-primary">
    <div class="box-header" style="cursor: move;">
        <i class="ion ion-clipboard"></i>

        <h3 class="box-title">结果</h3>

        <div class="box-tools pull-right">
            <?php echo $entries->links(); ?>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <ul class="todo-list ui-sortable">
            <table class="table table-hover">
                <tbody><tr>
                    <th class="col-xs-2">{{ Form::orderLink($links, Food::$column['name'], 'name') }}</th>
                    <th class="col-xs-2">{{ Form::orderLink($links, Food::$column['original_price'], 'original_price', true) }}</th>
                    <th class="col-xs-2">{{ Form::orderLink($links, Food::$column['price'], 'price', true) }}</th>
                    <th class="col-xs-1">{{ Form::orderLink($links, Food::$column['count'], 'count', true) }}</th>
                    <th class="col-xs-1">{{ Form::orderLink($links, Food::$column['status'], 'status') }}</th>
                    <th class="col-xs-2">{{ Form::orderLink($links, Food::$column['created_at'], 'created_at', true) }}</th>
                    <th class="col-xs-2">{{{ Lang::get('table.actions') }}}</th>
                </tr>
                @foreach ($entries as $entry)
                <tr>
                    <th class="col-xs-2">{{ $entry->name }}</th>
                    <th class="col-xs-2">{{ $entry->original_price }}</th>
                    <th class="col-xs-2">{{ $entry->price }}</th>
                    <th class="col-xs-1">{{ $entry->count }}</th>
                    <th class="col-xs-1">{{ Food::$statuses[$entry->status]['display_name'] }}</th>
                    <th class="col-xs-2">{{ $entry->created_at }}</th>
                    <th class="col-xs-2">
                        @if (Auth::user()->can('update_food'))
                        <a href="{{{ URL::action('BackFoodController@doUpdate', $entry->id) }}}" class="iframe btn btn-xs btn-default"><i class="fa fa-edit"></i> {{{ Lang::get('button.edit') }}}</a>
                        @elseif (Auth::user()->can('show_food'))
                        <a href="{{{ URL::action('BackFoodController@doUpdate', $entry->id) }}}" class="iframe btn btn-xs btn-default"><i class="fa fa-eye"></i> {{{ Lang::get('button.view') }}}</a>
                        @endif
                        @if (Auth::user()->can('delete_food'))
                        <a href="#deleteModal" data-id="{{ $entry->id }}" data-toggle="modal" class="iframe btn btn-xs btn-danger"><i class="fa fa-trash-o"></i> {{{ Lang::get('button.delete') }}}</a>
                        @endif
                    </th>
                </tr>
                @endforeach
                </tbody></table>

        </ul>
    </div>
    <!-- /.box-body -->
    <div class="box-footer clearfix no-border">
        @if (Auth::user()->can('create_food'))
        <a href="{{{ URL::to('back_end/foods/create') }}}" class="btn btn-default pull-right"><i class="fa fa-plus"></i><i class="icon-plus-sign"></i> {{{ Lang::get('button.create') }}}</a>
        @endif
    </div>
</div>

<!-- Modal -->
<div id="deleteModal" class="modal fade" tabindex="-1" food="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">确认删除</h3>
            </div>
            <div class="modal-body">
                <p>确认删除这条信息?</p>
            </div>
            <div class="modal-footer">
                <form id="deleteForm" class="form-horizontal" method="post" action="" autocomplete="off">
                    <!-- CSRF Token -->
                    <input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
                    <input type="hidden" name="id" value="" />
                    <button class="btn" data-dismiss="modal" aria-hidden="true">{{{ Lang::get('button.cancel') }}}</button>
                    <button type="submit" class="btn btn-primary">{{{ Lang::get('button.ok') }}}</button>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- Modal End -->
@stop

{{-- Scripts --}}
@section('scripts')
<script type="text/javascript">
    $(function () {

        'use strict';

        $('input[name="created_at_start"]').datetimepicker({
            format: 'yyyy-mm-dd',
            language:'zh-CN',
            minView:'month',
            startView:'month',
            startDate: "1970-01-01",
            endDate: "2115-01-01"
        });
        $('input[name="created_at_end"]').datetimepicker({
            format: 'yyyy-mm-dd',
            language:'zh-CN',
            minView:'month',
            startView:'month',
            startDate: "1970-01-01",
            endDate: "2115-01-01"
        });
        $('.fa-calendar').parent('div').click(function(){
            $('input[name="created_at_start"]').datetimepicker('show');
            $('input[name="created_at_end"]').datetimepicker('show');
        });

        var deleteAction = "{{ URL::to('back_end/foods/delete') }}";
        $('a[data-toggle="modal"]').click(function(){
            if(deleteAction){
                $('form#deleteForm').attr('action',  deleteAction + '/' + $(this).attr('data-id'));
                $('form#deleteForm input[name="id"]').attr('value',  $(this).attr('data-id'));
            }
        });

        $('form button.btn-export').click(function(event){
            event.preventDefault();
            $('.box-search form').attr('target', "_blank");
            $('.box-search form').attr("action","{{ URL::to('back_end/foods/export') }}?type="+$(this).attr('data-type'));
            $('.box-search form').submit();
        });

        $('form button.btn-find').click(function(event){
            event.preventDefault();
            $('.box-search form').attr('target', "_self");
            $('.box-search form').attr("action","{{ URL::to('back_end/foods') }}");
            $('.box-search form').submit();
        });

    });
</script>
@stop
